$(function(){

   // $('.wContent').hide();
    $('.headerSwitch').click(function(){
        $(this).parent().parent().find(".wContent").slideToggle("slow");
    }) ;
   
   $('input').keyup(function(){
       $(this).parent().find('span').hide();

   });
});
 
 function saveProfile()
 {
                                                                                                     
    var name = $.trim($('#uName').val());
    var email = $.trim($('#uEmail').val());    
    var mobile =$.trim($('#uMobilePhone').val());
    var ulang= $('#uLang').prop("selectedIndex");
    var uDept= $('#uDept').prop("selectedIndex");
    var isError =false;    

    if (name=="")
    {
         showError($('#uName').parent().find('.errorMsg'));        
         isError  =true;;
    }
    
    if (email.match(/^([\w]+)(.[\w]+)*@([\w]+)(.[\w]{2,3}){1,2}$/)==null)
    {
        showError($('#uEmail').parent().find('.errorMsg'));        
         isError  =true;;
    }
    if (mobile!= "" && mobile.match(/^6?01\d{8,9}$/)==null)    
    {
        showError($('#uMobilePhone').parent().find('.errorMsg'));
         isError  =true;;
    }
    
    console.log('mobile'+mobile+',email:'+email+',lang:'+ulang+',dept:'+uDept);
          
    if (isError) return ;
    ulang++;
    uDept++;
    var url =  window.location.href + '/ajaxSaveProfile';    
    $.post(url ,{name:name,email:email,mobile:mobile,lang:ulang,dept:uDept},
        function(data){                         
            showError($('#saveProfile .errorMsg'),'    ' + data.status,5000);            
          },"json");    
 };         
                                                     
                                                     
                                                     
function showError(ele, msg,fadeout)
{
    if(typeof msg!= 'undefined') ele.text(msg);
    ele.fadeIn("fast");
    if (typeof fadeout != 'undefined')
    { 
        setTimeout(function(){
            ele.fadeOut(fadeout);
        },2000)
    }    
} 
 function changePsw()
{
    var oldpsw = $.trim($('#password_old').val());
    var newpsw = $.trim($('#password_new').val());
    var newpsw2 = $.trim($('#password_confirm').val());
    if (oldpsw =="" )
    {
        showError($('#password_old').parent().find('.errorMsg'));        
        return ;
    }
    if (newpsw =="" )
    {
        showError($('#password_new').parent().find('.errorMsg'));
        return ;
    }
    if (newpsw.length <5)
    {
        
        showError($('#psw2Short'));
        return ;
    }
    if (newpsw != newpsw2 )
    {
        showError($('#password_confirm').parent().find('.errorMsg'));
        return ;
    }
                                            
    var url =  window.location.href + '/ajaxChangePassword';    
    $.post(url ,{"oldpsw":oldpsw,"newpsw":newpsw },
        function(data){                         
                if(data.status =='ok')
                    alert("ok");
                else
                    alert('ajax error');
          },"json");    
}
